package com.zp.crm.Controller.KhController;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.google.gson.Gson;
import com.zp.crm.entity.KhEntity.KhEntity;
import com.zp.crm.service.KhService.KhService;

@Controller
@RequestMapping("/kh")
public class KhController {
	@Resource
	public KhService khService;
	
	
	
	@RequestMapping(value="/select",method=RequestMethod.POST)
	public void KhSelectList(HttpServletRequest request,HttpServletResponse response,Model model){
		response.setContentType("text/html;charset=utf-8");
		String pageStr=request.getParameter("page");
		String stuts=request.getParameter("stuts");
		int page=1;int size=10;
		if(pageStr != null && !pageStr.equals("0")){
			page=Integer.parseInt(pageStr);
		}
		Map<String,Object> map=khService.selectPage(page,size,stuts);
		String a=(String)map.get("message");
		try{
			PrintWriter out =response.getWriter();
			out.println(a);
		}catch (Exception e) {
			e.printStackTrace();
		}		
	}
	@RequestMapping(value="/selectcreate",method=RequestMethod.POST)
	public void KhSelectCreateListPage(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String pageStr=request.getParameter("page");
		String code=request.getParameter("code");
		String name=request.getParameter("name");
		String dq=request.getParameter("dq");
		String stuts=request.getParameter("stuts");
		int page=0,size=10;
		if(pageStr != null && !pageStr.equals("0")){
			page=Integer.parseInt(pageStr);
		}
		Map<String,Object> map=khService.selectCreatePage(code,name,dq,page,size,stuts);
		String a=(String)map.get("message");
		try{
			PrintWriter out =response.getWriter();
			out.println(a);
		}catch (Exception e) {
			e.printStackTrace();
		}	
	}
	@RequestMapping(value="/selectbycode",method=RequestMethod.POST)
	public void SelectByCode(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String code=request.getParameter("code");
		Map<String,Object> map=khService.selectBycode(code);
		try{
			PrintWriter out =response.getWriter();
			String json=new Gson().toJson(map);
			out.println(json);
		}catch (Exception e) {
			e.printStackTrace();
		}	
	}
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public void edit(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String code=request.getParameter("code");
		String crmName=request.getParameter("crmName");
		String crmdq=request.getParameter("crmdq");
		String crmdj=request.getParameter("crmdj");
		String crmmyd=request.getParameter("crmmyd");
		String crmxyd=request.getParameter("crmxyd");
		String crmusername=request.getParameter("crmusername");
		String crmdz=request.getParameter("crmdz");
		String crmyzbm=request.getParameter("crmyzbm");
		String crmphone=request.getParameter("crmphone");
		String crmcz=request.getParameter("crmcz");
		String crmwz=request.getParameter("crmwz");
		String crmyyzz=request.getParameter("crmyyzz");
		String crmfr=request.getParameter("crmfr");
		String crmzczj=request.getParameter("crmzczj");
		String crmnyye=request.getParameter("crmnyye");
		String crmkhyh=request.getParameter("crmkhyh");
		String crmyhzh=request.getParameter("crmyhzh");
		String crmdsdjh=request.getParameter("crmdsdjh");
		String crmgsdjh=request.getParameter("crmgsdjh");
		KhEntity entity=new KhEntity(code, crmName, crmdq, crmdj, crmmyd, crmxyd, crmusername, crmdz, crmyzbm, crmphone, crmcz, crmwz, crmyyzz, crmfr, Float.parseFloat(crmzczj), Float.parseFloat(crmnyye), crmkhyh, crmyhzh, crmdsdjh, crmgsdjh);
		Map<String, Object> map=khService.edit(entity);
		try {
			PrintWriter out=response.getWriter();
			String json=new Gson().toJson(map);
			out.println(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public void KhDelete(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String code=request.getParameter("code");
		Map<String, Object> map=khService.delete(code);
		try {
			PrintWriter out=response.getWriter();
			String json=new Gson().toJson(map);
			out.println(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value="/insert",method=RequestMethod.POST)
	public void Insert(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String code=request.getParameter("code");
		String crmName=request.getParameter("crmName");
		String crmdq=request.getParameter("crmdq");
		String crmdj=request.getParameter("crmdj");
		String crmmyd=request.getParameter("crmmyd");
		String crmxyd=request.getParameter("crmxyd");
		String crmusername=request.getParameter("crmusername");
		String crmdz=request.getParameter("crmdz");
		String crmyzbm=request.getParameter("crmyzbm");
		String crmphone=request.getParameter("crmphone");
		String crmcz=request.getParameter("crmcz");
		String crmwz=request.getParameter("crmwz");
		String crmyyzz=request.getParameter("crmyyzz");
		String crmfr=request.getParameter("crmfr");
		String crmzczj=request.getParameter("crmzczj");
		String crmnyye=request.getParameter("crmnyye");
		String crmkhyh=request.getParameter("crmkhyh");
		String crmyhzh=request.getParameter("crmyhzh");
		String crmdsdjh=request.getParameter("crmdsdjh");
		String crmgsdjh=request.getParameter("crmgsdjh");
		KhEntity entity=new KhEntity(code, crmName, crmdq, crmdj, crmmyd, crmxyd, crmusername, crmdz, crmyzbm, crmphone, crmcz, crmwz, crmyyzz, crmfr, Float.parseFloat(crmzczj), Float.parseFloat(crmnyye), crmkhyh, crmyhzh, crmdsdjh, crmgsdjh);
		Map<String, Object> map=khService.insert(entity);
		try {
			PrintWriter out=response.getWriter();
			String json=new Gson().toJson(map);
			out.println(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
